package com.example.myapplication;

import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.collection.ArraySet;

import java.util.ArrayList;

public class DuoChoiceDialogFragment extends DialogFragment {
    private String[] genders = new String[]{"男", "女"};
    private ChoiceDialogFragment.NotifyDialogListener listener;

    public interface NotifyDialogListener {
        public void onDialogPositiveClicked(String gender);
    }

    public void setListener(ChoiceDialogFragment.NotifyDialogListener listener) {
        this.listener = listener;
    }

    public Dialog onCreateDialog(Bundle savedInstanceState) {
        
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle("多选对话框")
                .setMultiChoiceItems(genders, null, new DialogInterface.OnMultiChoiceClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                        ArrayList selectedItems = new ArrayList();
                        if(isChecked){
                            selectedItems.add(genders[which]);
                        }else {
                            selectedItems.remove(genders[which]);
                        }
                    }
                });
        return builder.create();
    }
}